﻿//  [ ] \  正则表达式保留    #号,号,&,|号  系统保留   <> sql注入不允许
var permit_sCharacter_en = "`~!@$%^*;:\/.(){}?_\+\=";
var permit_sCharacter_cn = "·~！@￥%……*（）：”；‘《》？，。、=_+";
var permit_sCharacter = permit_sCharacter_en + permit_sCharacter_cn;  //除英文  #号,号,&,|号  外的字符

//全局的ajax访问，处理ajax清求时sesion超时
$.ajaxSetup({
    contentType: "application/x-www-form-urlencoded;charset=utf-8",
    cache: false,
    complete: function (XMLHttpRequest, textStatus) {
        var resText = XMLHttpRequest.responseText;
        if (resText != null && resText != "") {
            if (resText == "{sessionState:0}") {
                alert("登录时间超时或没有权限，请关闭浏览器重新登录");
                window.location.href = "portal/wtdl.jsp";
            }
        }
    }
});

//重写分页
if ($.fn.pagination) {
    $.fn.pagination.defaults.total = 0;
    //$.fn.pagination.defaults.displayMsg='显示{from}到{to},共{total}条记录';
    $.fn.pagination.defaults.beforePageText = '页 ';
    $.fn.pagination.defaults.afterPageText = '共{pages}页';

}


// 弹出中型窗口相关，idname,divName,窗口宽度，窗口高度，窗口起点系统固定
function showWin(idName, width, height, top) {
    //alert("divName=" + idName + " width=" + width + " height=" + height);
    var winName = "#" + idName;
    $(winName).window({
        width: width,
        modal: true,
        shadow: false,
        closed: false,
        collapsible: false,
        minimizable: false,
        maximizable: false,
        closable: true,
        height: height,
        top: top
    });
}
//弹出中型窗口相关，idname
function showDeptWin(idName) {
    var winName = "#" + idName;
    $(winName).window({
        height: 300,
        width: 300,
        modal: true,
        shadow: false,
        closed: false,
        collapsible: false,
        minimizable: false,
        maximizable: false,
        closable: true
    });
}
//function hideWin(idName) {
//var winName = "#" + idName;
//$(winName).window('destroy');
//}
function hideWin(idName) {
    var winName = "#" + idName;
    $(winName).window({
        closed: true
    });
}

function changeStatus() {
    if (true) {
        $.messager.confirm('确定', '确定要启用/停用/注销... 用户/管理员/凭证... 信息?', function (r) {
            if (r) {
                $.messager.alert('提示信息', '启用/停用/注销...成功', 'info');
            }
        });
    }
}

function linkto(url) {
    window.location.href = url;
}


function jgtree() {
    var obj = new Object();
    window.showModalDialog("jgtree.htm", obj, "dialogWidth=200px;dialogHeight=300px");
}
//给radio对象赋值 arrayObj radio 对象  checkValue 预期点选项的value值。
function setRadioValue(arrayObj, checkValue) {
    for (var i = 0; i < arrayObj.length; i++) {
        if (checkValue == arrayObj[i].value) {
            //alert(i+"为初始化 appType");
            arrayObj[i].checked = true;
        }
    }
}
/**
 * 获得check 控件选择列表，选择对象之间以 ,号分隔
 * */
function getCheckedValue(checkboxName) {
    var resultStr = "";
    var checkArray = document.getElementsByName(checkboxName);
    //alert(checkArray.length);
    for (var i = 0; i < (checkArray.length); i++) {
        //alert(i+"是否选中"+seletedAp[i].checked+"    "+toSystempFlowno.length);
        if (checkArray[i].checked) {
            if (resultStr.length == 0) {
                resultStr = checkArray[i].value;
            } else {
                resultStr = resultStr + "," + checkArray[i].value;
            }
        }
    }
    return resultStr;
}

//将日期Date格式化
Date.prototype.format = function(fmt)
{
    var o = {
        "M+" : this.getMonth()+1,                 //月份
        "d+" : this.getDate(),                    //日
        "h+" : this.getHours(),                   //小时
        "m+" : this.getMinutes(),                 //分
        "s+" : this.getSeconds(),                 //秒
        "q+" : Math.floor((this.getMonth()+3)/3), //季度
        "S"  : this.getMilliseconds()             //毫秒
    };
    if(/(y+)/.test(fmt))
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)
        if(new RegExp("("+ k +")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
    return fmt;
}

//获得对象的类型
function getType(x) {
    if (x == null) {
        return "null";
    }
    var t = typeof x;
    if (t != "object") {
        return t;
    }
    var c = Object.prototype.toString.apply(x);
    c = c.substring(8, c.length - 1);
    if (c != "Object") {
        return c;
    }
    if (x.constructor == Object) {
        return c
    }
    if ("classname" in x.prototype.constructor
        && typeof x.prototype.constructor.classname == "string") {
        return x.constructor.prototype.classname;
    }
    return "<unknown type>";
}


//判断开始日期是否早于结束日期  必须为用控件输入的日期格式为　yyyy-mm-dd
function compareDate(firStr, lasStr) {
    // alert("firStr="+firStr+"    lasStr="+lasStr);
    var arrFir = new Array();
    arrFir = firStr.split("-");
    var first = arrFir[0] + arrFir[1] + arrFir[2];
    var arrLas = new Array();
    arrLas = lasStr.split("-");
    var last = arrLas[0] + arrLas[1] + arrLas[2];

    if (arrFir.length > 1 && arrLas.length > 1) {
        return (parseInt(first) - parseInt(last)) <= 0;
    }
    else {
        return true;
    }

}
/*
 * author:孙宇  夏悸
 * 将form 表单里的对象序列化
 * */
function serializeObject(form) {
    var o = {};
    $.each(form.serializeArray(), function (index) {
        if (o[this['name']]) {
            o[this['name']] = o[this['name']] + "," + this['value'];
        } else {
            o[this['name']] = this['value'];
        }
    });
    return o;
}

/**
 * 比较IP大小
 * @author liwei
 * @param ipBegin
 * @param ipEnd
 * @returns {number} 0:equal 1:larger -1:smaller
 */
function compareIP(ipBegin, ipEnd) {
    var temp1;
    var temp2;
    temp1 = ipBegin.split(".");
    temp2 = ipEnd.split(".");
    for (var i = 0; i < 4; i++) {
        if (Number(temp1[i]) > Number(temp2[i])) {
            return 1;
        }
        else if (Number(temp1[i]) < Number(temp2[i])) {
            return -1;
        }
    }
    return 0;
}

/**
 * 防止backspace键后退浏览器
 */
function preventDefault_BackSpace() {
    if (event.keyCode == 8) {
        event.returnValue = false;
    }
}

/**
 * 必须bind到button上
 */
function reset_form() {
    $(this).closest("form").each(function () {
        this.reset();
        $(this).find("input[type='hidden']").val('');
    });
}
/**
 * 全选/反选机构
 * @param selected
 * @param tree_id
 */
function checkAll(selected,tree_id){
    if (selected.checked) {
        $('#'+tree_id).tree('checkAll');
    }else{
        $('#'+tree_id).tree('unCheckAll');
    }
}
/**
 * datagrid单元格字符过长显示
 * @param value
 * @param rec
 * @returns {string}
 */
function datagrid_cell_title_display(value,rec){
    return "<span title="+value+">"+value+"</span>";
}